package main

import (
	"fmt"
	"strings"
)

func checkPasswordStrength(password string) (int, []string) {
	score := 2
	improvements := []string{}

	// 1. 长度超过8位
	if len(password) > 8 {
		score++
	} else {
		improvements = append(improvements, "密码长度应该超过8位")
	}

	// 2. 包含大、小写字母、数字、其他符号中的至少三种
	characterTypes := map[string]bool{
		"lowercase": strings.ContainsAny(password, "abcdefghijklmnopqrstuvwxyz"), // 小写字母
		"uppercase": strings.ContainsAny(password, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"), // 大写字母
		"number":    strings.ContainsAny(password, "0123456789"),                 // 数字
		"symbol":    strings.ContainsAny(password, "!@#$%^&*()_+{}[],./?<>;:'\"\\|"), // 其他符号
	}
	count := 0
	for _, t := range characterTypes {
		if t {
			count++
		}
	}
	if count >= 3 {
		score++
	} else {
		improvements = append(improvements, "密码必须包含至少三种字符类型：大写字母、小写字母、数字和特殊符号")
	}

	// 3. 不能有长度超过或等于3的字串重复
	for i := 0; i < len(password)-2; i++ {
		if strings.Contains(password[i+1:], password[i:i+3]) {
			score--
			improvements = append(improvements, "密码不能有长度超过或等于3的字串重复")
			break
		}
	}

	return score, improvements
}

func main() {
	var password string
	fmt.Print("请输入密码：")
	fmt.Scanln(&password)
	score, improvements := checkPasswordStrength(password)
	fmt.Println("密码评分：", score)
	fmt.Println("改进点：", improvements)
}
